package com.jjc.android.dialog

import android.content.Context
import android.view.View
import android.widget.TextView
import com.allen.library.SuperButton
import com.jjc.android.R
import com.jjc.android.view.onClick
import com.jjc.android.view.textChange
import com.lxj.xpopup.core.BottomPopupView
import com.xw.repo.XEditText

class InputTextDialog(context: Context, private val action:(String)->Unit) : BottomPopupView(context) {
    private lateinit var okBtn: SuperButton
    private lateinit var googleCodeEt: XEditText
    private lateinit var closeBtn: TextView

    private fun initViews(view: View) {
        closeBtn = view.findViewById(R.id.close_btn)
        googleCodeEt = view.findViewById(R.id.googleCodeEt)
        okBtn = view.findViewById(R.id.okBtn)
    }

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_input_text
    }

    override fun onCreate() {
        super.onCreate()
        initViews(this)
        closeBtn.onClick {
            dismiss()
        }
        googleCodeEt.textChange {
            okBtn.isEnabled = !it.isNullOrEmpty()
        }
        okBtn.onClick {
            action.invoke(googleCodeEt.textEx)
            dismiss()
        }
    }

}